//CustomClass Template - Created by CodenameGamma
//Replace Layout with the CC name, 
//and WoWClass.Mage with the Class your Designing for.
//Created July, 3rd 2010
//For use with Honorbuddy
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Styx;
using Styx.Combat.CombatRoutine;
using Styx.Helpers;
using Styx.Logic;
using Styx.Logic.Combat;
using Styx.Logic.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using HBPVPDruid;
using HBPVPDruid.Misc;
using HBPVPDruid.Spells;

namespace HBPVPDruid
{
    public partial class PVPDruid : CombatRoutine
    {
        private readonly Version _versionNumber = new Version(1, 0, 0, 4); 
        public override sealed string Name { get { return "HBPVPDruid [" + _versionNumber + "] By SwInY"; } }
        public override WoWClass Class { get { return WoWClass.Druid; } }
        private static LocalPlayer Me { get { return ObjectManager.Me; } }

        private static Stopwatch Timerz = new Stopwatch();

        public static void DoCombat()
        {
            // Our combat loop 
            // Might lock everything else up, but fuck em.
            //  we need our process running fast for movement
            do
            {
                WoWUnit Player;

                if (Battlegrounds.IsInsideBattleground)
                {
                    Player = GetTargetPlayer.TargetPlayer();
                } else {
                    Player = Me.CurrentTarget;
                    if (Misc.Misc.NPCMisc.EnemyAttackingMe == 1) GetTargetPlayer.SingleTarget = true;
                }

                // If no player what are we doing!
                //if (Player == null) Me.ClearTarget();
                if (Player == null) return;
                if (Player == null) { if (Me.MovementInfo.IsStrafing) WoWMovement.MoveStop(); }
                if (!Player.Attackable) return;

                Player.Target();
                Player.Face();

                // Movement
                if ( Config.DoRandomStrafing == true) Movement.MovementSleep.Pulse(Player);
                Movement.MovementSleep.CheckDistance(Player);

                Player.Face();

                // Checks
                if (StyxWoW.GlobalCooldown) return;
                if (Me.IsCasting) return;
                if (!Me.IsAlive) return;
                if (Me.Stunned) return;

                // Clear target if further than our range, need a new person ;)
                if (Player.Distance >= 40) { Me.ClearTarget(); return; }

                // Check Form
                CheckForm();

                // Globals
                if (Spells.Defensives.Barkskin.Pulse()) return;
                if (Spells.Defensives.Thorns.Pulse()) return;
                if (Spells.Starsurge.Pulse(Player)) return;
                if (Spells.ForceofNature.Pulse(Player)) return;
                if (Spells.Starfall.Pulse()) return;
                if (Spells.Typhoon.Pulse(Player)) return;

                // Dots
                if (Spells.Moonfire.Pulse(Player, GetTargetPlayer.SingleTarget)) return;
                if (Spells.InsectSwarm.Pulse(Player)) return;

                if (Spells.Wrath.Pulse(Player)) return;
                if (Spells.Starfire.Pulse(Player)) return;

            } while (Me.IsActuallyInCombat);
        }

        private static void CheckForm()
        {
            if (Me.IsCasting) return;
            if (Me.Shapeshift == Styx.ShapeshiftForm.Moonkin) return;

            WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend, TimeSpan.FromSeconds(1));
            SpellManager.Cast("Moonkin Form");
            WoWMovement.MoveStop();
        }

        
        #region CombatBuff
        public override bool NeedCombatBuffs  
        { 
            get 
            {
                if (Me.IsCasting) return false;
                if (Me.Shapeshift != Styx.ShapeshiftForm.Normal) return false;
                if (Me.Shapeshift == Styx.ShapeshiftForm.Moonkin) return false;

                return true;
            } 
        }
        public override void CombatBuff()
        {
            CheckForm();
        }
        #endregion


        public override void Pulse() { DoCombat(); }
        public override void Pull() { DoCombat(); }
        public override void Combat() { DoCombat(); }


        #region Spells


        private void AutoAttack()
        {
            if (!Me.IsAutoAttacking)
            {
                Lua.DoString("StartAttack()");
            }

        }
      #endregion
    }   
}
